package com.example.app7.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.example.app7.MyData;
import com.example.app7.R;

import java.util.List;

public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {

    private List<MyData> imageItems;
    private Context context;

    public ImageAdapter(Context context,List<MyData> items) {
        this.imageItems = items;
        this.context = context;
    }

    @NonNull
    @Override
    public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.imagen, parent, false);
        ImageViewHolder myViewHolder = new ImageViewHolder(view);

        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
        MyData o = (MyData) imageItems.get(position);

        Log.d("service", "适配器: "+position);

        holder.imageView.setText(o.getName());




    }

    @Override
    public int getItemCount() {
        return imageItems.size();
    }

    static class ImageViewHolder extends RecyclerView.ViewHolder {
        TextView imageView;


        public ImageViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.images);
        }


    }
}
